// packageA/pages/cashService/operator/orderConfirm/orderConfirm.js
const util = require('../../../../utils/util.js')
const { imgPath } = require('../../../../utils/request')
const { request } = require('../../../../utils/request');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: imgPath,
    userInfo:{},
    bagList: [],
    sumMoney: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '订单'
    })
    
    if(wx.getStorageSync('tempBagList')){
      this.setData({
        bagList:wx.getStorageSync('tempBagList')
      })
      wx.removeStorageSync('tempBagList')
    }
    
    let money = 0
    this.data.bagList.forEach(item => {
      money = money + Number(item.inputAmount)
    })
    this.setData({
      sumMoney: money,
      userInfo:wx.getStorageSync('userInfo')
    })
  },
  /**
   * 确认提交订单
   */
  send2Bank(){
    let tempIds = []
    this.data.bagList.forEach(item=>{
      tempIds.push(item.id)
    })
    request('/smsk/wechat/orderinfo/submit', 'POST', {ids:tempIds}).then(res => {
      console.log(res.data)
      if (res.data.code === 0) {
        wx.showToast({
          title: '提交成功',
          icon: 'success'
        })
        setTimeout(() => {
          wx.setStorageSync('tempTabId', '2')
          wx.navigateBack({
            delta: 1,
          })
        }, 1500);
      } else {
        console.log(res.data)
        wx.showToast({
          title: '提交失败',
          icon: 'error'
        })
      }
    })
  }
})